package com.snail.poker.web;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.time.DateUtils;

import com.snail.poker.uitls.DateUtil;

/**
 * 分页数据上下文 <br/>
 * offset 和 pagesize 由拦截器负责获取, 并放入ThreadLocal中, 方便dao层获取数据
 * 
 * @author 黄珍辉
 * 
 */
public class PageContext {
	private static ThreadLocal<Integer> threadOffset = new ThreadLocal<Integer>();
	private static ThreadLocal<Integer> threadPagesize = new ThreadLocal<Integer>();
	private static ThreadLocal<Date> threadBeginTime = new ThreadLocal<Date>();
	private static ThreadLocal<Date> threadEndTime = new ThreadLocal<Date>();

	public static void clean() {
		threadOffset.remove();
		threadPagesize.remove();
		threadBeginTime.remove();
		threadEndTime.remove();
	}

	public static int getOffset() {
		Integer valueObj = threadOffset.get();
		if (valueObj == null)
			return 0;

		return valueObj.intValue();
	}

	public static void setOffset(int value) {
		threadOffset.set(value);
	}

	public static int getPageSize() {
		Integer ps = threadPagesize.get();
		if (ps == null) {
			return 50;
		}
		return ps;
	}

	public static void setPageSize(int value) {
		threadPagesize.set(value);
	}

	public static Date getBeginTime() {
		Date begin = threadBeginTime.get();
		return begin;
	}

	public static void setBeginTime(Date value) {
		threadBeginTime.set(value);
	}

	public static Date getEndTime() {
		Date end = threadEndTime.get();
		return end;
	}

	public static void setEndTime(Date value) {
		threadEndTime.set(value);
	}
}
